In [11]:
import pandas as pd
import seaborn as sns
In [12]:
df = sns.load_dataset("titanic")
In [13]:
df.head()
Out[13]:
survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
In [14]:
sns.barplot(x ="class", y= "age", data = df)
Out[14]:
<Axes: xlabel='class', ylabel='age'>
In [29]:
sns.barplot(x ="class", y= "age",hue = "sex", data = df)
Out[29]:
<Axes: xlabel='class', ylabel='age'>
In [6]:
sns.barplot(x ="class", y= "age",hue = "sex",estimator="sum", data = df)
Out[6]:
<Axes: xlabel='class', ylabel='age'>
In [19]:
sns.boxplot(x = "sex", y= "age", data = df)
Out[19]:
<Axes: xlabel='sex', ylabel='age'>
In [20]:
sns.boxplot(x = "sex", y= "age", hue = "class", data = df)
Out[20]:
<Axes: xlabel='sex', ylabel='age'>
In [25]:
sns.histplot(df[df["survived"]==0]["age"], kde=True, stat="density", linewidth=0)
sns.histplot(df[df["survived"]==1]["age"], kde=True, stat="density", linewidth=0)
Out[25]:
<Axes: xlabel='age', ylabel='Density'>
In [26]:
sns.violinplot(x = "sex", y = "fare", data = df)
Out[26]:
<Axes: xlabel='sex', ylabel='fare'>
In [27]:
df
Out[27]:
survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
886 | 0 | 2 | male | 27.0 | 0 | 0 | 13.0000 | S | Second | man | True | NaN | Southampton | no | True |
887 | 1 | 1 | female | 19.0 | 0 | 0 | 30.0000 | S | First | woman | False | B | Southampton | yes | True |
888 | 0 | 3 | female | NaN | 1 | 2 | 23.4500 | S | Third | woman | False | NaN | Southampton | no | False |
889 | 1 | 1 | male | 26.0 | 0 | 0 | 30.0000 | C | First | man | True | C | Cherbourg | yes | True |
890 | 0 | 3 | male | 32.0 | 0 | 0 | 7.7500 | Q | Third | man | True | NaN | Queenstown | no | True |
891 rows × 15 columns
In [ ]:
sns.s